package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.Activity;
import com.xiaoma.tpo.dto.ActivityDto;

@Repository
public class ActivityDao extends BaseDaoImpl<Activity> {

	@SuppressWarnings("unchecked")
	public List<ActivityDto> findAll(Integer pageNum, Integer pageSize) {

		String sql = "select activity.*, type.name from activity, activity_type type"
				+ " where activity_type_id = type.id and activity.is_delete=0 limit ?,?";
		List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(
				ActivityDto.class, getNameHandler()), (pageNum - 1) * pageSize, pageSize);

		return (List<ActivityDto>) list;
	}
	
	@SuppressWarnings("unchecked")
	public List<Activity> findAll() {
		String sql = "select * from activity where is_delete=0 order by id desc";
		List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(
				Activity.class, getNameHandler()));

		return (List<Activity>) list;
	}
}
